package nl.haemers.test.griditem 
{
	import flash.display.Graphics;
	import flash.events.MouseEvent;
	import nl.haemers.components.grid.GridItem;
	import flash.display.Sprite;
	
	/**
	 * ...
	 * @author Jonathan Haemers
	 */
	public class CustomGridItem extends GridItem 
	{
		private var _background:Sprite;
		public function CustomGridItem(data:* = null, width:Number = NaN, height:Number = NaN) 
		{
			super(data, width, height);
		}
		
		/** Public methods **/
		public function render(container:Sprite) : void
		{
			if (this.rect)
			{
				container.graphics.lineStyle(2, 0xFF0000, 1);
				container.graphics.drawRect(this.rect.x, this.rect.y, this.rect.width, this.rect.height);
				//container.graphics.drawCircle(this.rect.x + this.rect.width * .5, this.rect.y+ this.rect.height * .5, this.rect.width * .5);
				
				var background:Sprite = new Sprite();
				background.graphics.beginFill(0x00FF00, .5);
				background.graphics.lineStyle(2, 0xFF0000, 1);
				background.graphics.drawRect(0, 0, this.rect.width, this.rect.height);
				//background.graphics.drawCircle(this.rect.x + this.rect.width * .5, this.rect.y+ this.rect.height * .5, this.rect.width * .5);
				background.graphics.endFill();
				background.x = this.rect.x;
				background.y = this.rect.y;
				background.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
				background.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
				background.addEventListener(MouseEvent.CLICK, clickHandler);
				background.buttonMode = true;
				background.useHandCursor = true;
				
				container.addChild(background);
				_background = background;
				
				hideBackground();
			}
		}
		
		private function rollOverHandler(e:MouseEvent) : void
		{
			showBackground();
		}
		private function rollOutHandler(e:MouseEvent) : void
		{
			hideBackground();
		}
		private function clickHandler(e:MouseEvent) : void
		{
			trace(this.gridId);
		}
		
		public function showBackground() : void
		{
			this._background.alpha = 1;
			//this._background.visible = true;
		}
		
		public function hideBackground() : void
		{
			this._background.alpha = 0;
			//this._background.visible = false;
		}
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
		
	}

}